/**********************************************************************
 *
 *
 * @url: /services/apexrest/rest
 * @data:
 *  {

    }
*************************************************************************/
global class QueryPrictureOrVoiceService {
    private static String postURL = '';
    private static String key = '';
    static {
        WeiXinAPI__c wx = WeiXinAPI__c.getValues('queryFile');
      //  postURL = wx.URL__c;
        postURL = 'http://1n9i335363.imwork.net/maik-weixin/ws/Maike/queryFile';
        key = wx.Security__c;
    }

    /**
     * @param filetype:图片/语音
     * @param caseNumber:个案编号
     */
    WebService static String query(String filetype, String media) {
        String  json = '{"fileType":"' + filetype + '","Media":"' + media + '","timeStamp":"' + Datetime.now().getTime() + '"}';
        Blob hash = Crypto.generateDigest('MD5', Blob.valueOf(json + key));
        String md5 = EncodingUtil.convertToHex(hash);
        String strmd5 = 'json=' + json + '&sign=' + md5;
        String cipher = EncodingUtil.base64Encode(Blob.valueOf(strmd5));
        String endpoint = postURL + '?cipher=' + EncodingUtil.urlEncode(cipher, 'utf-8');
        return endpoint;
        // try {
        // } catch (Exception e) {
        //     System.debug(LoggingLevel.INFO, '*** 错误信息: ' + e.getMessage() );
        //     System.debug(LoggingLevel.INFO, '*** 错误跟踪: ' + e.getStackTraceString());
        //     // msg = Utils.getRestReturnMessage(false, e.getMessage() + ' - ' + e.getStackTraceString(),Datetime.valueOf(Utils.MIN_DATE_TIME));
        //     // return 'json=' + json + '\nkey=' + key + '\nEndpoint=' + postURL + '?cipher=' + cipher + '\n' + e.getMessage();
        //     return postURL + '?cipher=' + cipher;
        // }
    }
}